﻿<template>
	<div class="card-fill layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<el-form ref="formRefFrameworkUser" :model="stateFrameworkUser.vmModel" label-width="100px">
				<div style="margin-bottom: 10px">{{ $t('message.autotrans.SysBatchEditConfirm') }}</div>
				<el-row>
					<el-col :xs="24" :lg="12" class="mb20">
						<el-form-item
							ref="LinkedVM_SelectedFrameworkUserRolesIDs_FormItem"
							prop="LinkedVM.SelectedFrameworkUserRolesIDs"
							:label="$t('message.autotrans._Model_FrameworkUser_Role')"
						>
							<el-select v-model="stateFrameworkUser.vmModel.LinkedVM.SelectedFrameworkUserRolesIDs" multiple clearable>
								<el-option
									v-for="item in stateFrameworkUser.AllFrameworkUserRoles"
									:key="item.Value"
									:value="item.Value"
									:label="item.Text"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :lg="12" class="mb20">
						<el-form-item
							ref="LinkedVM_SelectedFrameworkUserGroupsIDs_FormItem"
							prop="LinkedVM.SelectedFrameworkUserGroupsIDs"
							:label="$t('message.autotrans._Model_FrameworkUser_Group')"
						>
							<el-select v-model="stateFrameworkUser.vmModel.LinkedVM.SelectedFrameworkUserGroupsIDs" multiple clearable>
								<el-option
									v-for="item in stateFrameworkUser.AllFrameworkUserGroups"
									:key="item.Value"
									:value="item.Value"
									:label="item.Text"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>

				<div style="text-align: right">
					<WtmButton @click="onSubmitFrameworkUser" type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top: 15px" />

					<WtmButton @click="onCloseFrameworkUser" type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top: 15px" />
				</div>
			</el-form>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="message.autotrans._Page_AdminFrameworkUserBatchEdit;false">
import { ElMessage, ElLoading } from 'element-plus';
import { reactive, ref, getCurrentInstance, onMounted } from 'vue';
import { frameworkuserApi } from '/@/api/_admin/frameworkuser';
import other from '/@/utils/other';
import { useRouter } from 'vue-router';
const ci = getCurrentInstance() as any;

// 定义变量内容
const formRefFrameworkUser = ref();
const stateFrameworkUser = reactive({
	vmModel: {
		LinkedVM: {
			SelectedFrameworkUserRolesIDs: [],
			SelectedFrameworkUserGroupsIDs: [],
		},
		Ids: [],
	},

	AllFrameworkUserRoles: [] as any[],
	AllFrameworkUserGroups: [] as any[],
});

// 取消
const onCloseFrameworkUser = () => {
	closeDialog();
};

// 提交
const onSubmitFrameworkUser = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

	formRefFrameworkUser.value?.validate((valid: boolean) => {
		if (valid) {
			frameworkuserApi()
				.batchedit(stateFrameworkUser.vmModel)
				.then(() => {
					ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
					emit('refresh');
					closeDialog();
				})
				.catch((error: any) => {
					other.setFormError(ci, error);
				})
				.finally(() => {
					loadingInstance.close();
				});
		} else {
			loadingInstance.close();
		}
	});
};

// 页面加载时
onMounted(() => {
	other.getSelectList('/api/_Admin/FrameworkUser/GetFrameworkRoles', [], false).then((x) => {
		stateFrameworkUser.AllFrameworkUserRoles = x;
	});
	other.getSelectList('/api/_Admin/FrameworkUser/GetFrameworkGroups', [], false).then((x) => {
		stateFrameworkUser.AllFrameworkUserGroups = x;
	});
	if (ci.attrs['wtmdata']) {
		stateFrameworkUser.vmModel.Ids = ci.attrs['wtmdata'];
	} else if (useRouter().currentRoute.value.query.id) {
		stateFrameworkUser.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh', 'closeDialog']);
// 关闭弹窗
const closeDialog = () => {
	emit('closeDialog');
};
// 暴露变量
defineExpose({});
</script>

<style scoped lang="scss"></style>
